package com.ttbj.product.systemlog.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ttbj.api.dto.Page;
import com.ttbj.api.dto.log.SystemLogDto;
import com.ttbj.api.exception.BusinessException;
import com.ttbj.api.systemlog.SystemLogService;
import com.ttbj.constant.PlatFormErrorCode;
import com.ttbj.systemlog.dao.SystemLogMapper;

@Service("systemLogService")
public class SystemLogServiceImpl implements SystemLogService{
	
	@Autowired
	private SystemLogMapper systemLogMapper;

	
	@Override
	public void addToSystemLogInfo(SystemLogDto systemLogDto) {
		if (null == systemLogDto) {
			throw new BusinessException("参数有误", PlatFormErrorCode.PARAM_IS_NULL.code());
		}
		int result = this.systemLogMapper.insertSystemLog(systemLogDto);
	}

	@Override
	public List<SystemLogDto> findOperationOrExceptionLog(Integer type, Page page) {
		if (type == 0 || type == 1) {
			List<SystemLogDto> systemLogDtos = this.systemLogMapper.queryOperationOrExceptionLog(type, page);
			return systemLogDtos;
		}else {
			throw new BusinessException("参数有误", PlatFormErrorCode.PARAM_IS_NULL.code());
		}
	}

	@Override
	public Integer findOperationOrExceptionLogCount(Integer type) {
		if (type == 0 || type == 1) {
			int count = this.systemLogMapper.queryOperationOrExceptionLogCount(type);
			return count;
		}else {
			throw new BusinessException("参数有误", PlatFormErrorCode.PARAM_IS_NULL.code());
		}
	}
}
